import { SetMetadata, createParamDecorator } from "@nestjs/common";

/**
 * @desc    关于用户权限的修饰器
 * @Roles   ["admin","user","anyone"]
 * @auther  gebeibei
 * @date 2019/07/22
 */
export const Roles = (...roles:string[]) => SetMetadata('roles',roles);

export const Authing = createParamDecorator((data,req)=>{
    return req.authing;
});

export const AuthUser = createParamDecorator((data,req)=>{
    let token = req.query.token || null;
    !token && (token = req.body.token);
    return req.authing.decodeToken(token);
})